<template>
	<view>
		<tab-nav :tabData="tabData" :tabIndex="tabIndex" @switchStaus="switchStatus"></tab-nav>
		<view class="cpWrap">
			<template v-if="isHasDataFlag">
				<cp-list currPage="myGy" :cpList="cpList" @goDet="goMyGyDet"></cp-list>
				<loading-view :loading="loading"></loading-view>
			</template>
			<template v-else-if="isHasDataFlag == false">
				<no-data></no-data>
			</template>
		</view>
	</view>
</template>

<script>
	import TabNav from '@/components/tab-nav/tab-nav.vue'
	import CpList from '../../index/components/CpList.vue'
	import { getMyGyList } from '@/api/mine/index.js'
	export default {
		components:{
			TabNav,
			CpList
		},
		data(){
			return{
				tabData:[
					// {id:0,name:'全部'},
					{id:1,name:'未干预'},
					{id:2,name:'干预中'},
					{id:3,name:'已完成'}
				],
				tabIndex:0,
				gyStatus:0,
				nowPage:1,
				loading:false,
				hasNextFlag:null,
				isHasDataFlag:null,
				cpList:[]
			}
		},
		onLoad(){
			this.getList();
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		onReachBottom : function(){
			if( !this.loading && this.hasNextFlag){
				this.getList();
			}
		},
		methods:{
			getList(){ 
				let { nowPage,cpList } = this;
				this.loading = true;
				let field = { gyStatus:this.gyStatus,page:this.nowPage,limit:this.limit }
				getMyGyList(field).then(res=>{
					//console.log(res)
					this.hasNextFlag = res.data.hasNext;
					nowPage += 1;
					cpList.push( ...res.data.datas );
					this.cpList = cpList; 
					this.nowPage = nowPage;
					this.loading = false;
					this.isHasDataFlag = true;
				}).catch(err=>{
					//console.log(err)
					this.loading = false;
					this.isHasDataFlag=false;
				});
			},
			switchStatus(index,id){
				this.tabIndex = index;
				this.gyStatus = id;
				this.initParams();
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.cpList = [];
				this.getList();
			},
			goMyGyDet(item){
				uni.navigateTo({
					url:'/pages/subMine/myGy/gyDet?logId=' + item.logId + '&detId=' + item.allotDetailId + '&fromPage=user&cpTit=' + item.scaleTitle
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: $pss-bg-primary;
	}
	.cpWrap{
		padding-top: 20rpx;
	}
</style>